package pt.ipleiria.plp;

import de.enough.polish.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;

/**
 * Class that contais the application key and the defines if the application
 * works on online or offline mode by default.
 * @author Filipe Felisberto e Ricardo Silva
 */
public class ApplicationData implements Serializable {

    private String app;
    private boolean onlineMode;
    private Vector tags;

    /**
     * Empty contructor
     */
    public ApplicationData() {
        app = null;
        onlineMode = false;
        tags = new Vector();
    }

    /**
     * Returns the current app key
     * @return the app
     */
    public String getApp() {
        return app;
    }

    /**
     * Sets the new app key
     * @param app the app to set
     */
    public void setApp(String app) {
        this.app = app;
    }

    /**
     * Returns if the default mode is online or offline
     * @return the onlineMode
     */
    public boolean isOnlineMode() {
        return onlineMode;
    }

    /**
     * Sets the new mode
     * @param onlineMode the onlineMode to set
     */
    public void setOnlineMode(boolean onlineMode) {
        this.onlineMode = onlineMode;
    }

    /**
     * Returns if the tags stored the cell phone mem
     * @return the tags
     */
    public String[] getTagsString(){
        Enumeration vals = tags.elements();

        String ret[] = new String[tags.size()];
        int i=0;
        while (vals.hasMoreElements()){

            ret[i] = (String)vals.nextElement();
            i++;
        }
        return ret;
    }
    /**
     * Adds a new tag to the stored tags
     * @param tag the tag to add
     */
    public void addTag(String tag){
        tags.addElement(tag);
    }

    /**
     * Removes a tag from the stored tags
     * @param tag the tag to remove
     */
    public boolean removeTag(String tag){
        return tags.removeElement(tag);
    }

    /**
     * Changes the stored tags for those recieved
     * @param tags the new tags
     */
    public void changeTags(String[] newTags){
        tags.removeAllElements();
        for(int i = 0 ; i<newTags.length; i++){

            tags.addElement(newTags[i]);

        }
    }
    /**
     * Gets the vector witht the tags, in normal OOP a copy with be sent, but
     * due to performance issues the vector itself will be sent.
     *
     * @return the vector with the tags
     */
    public Vector getTags(){
        return tags;
    }

}
